import Mock from 'mockjs'
var userList = Mock.mock({
  'list|20': [{
    'id|+1': 1,
    'account': '@name()',
    'realName': '@cname()',
    'roles|3': [{
      'roleName|1': ['超级管理员', '管理员', '普通用户'],
      'roleId': '10000@id'
    }],
    'accountStatus|1': [0, 1],
    'nickName': "@cword(0,10)",
    'mobile': /^1(5|3|7|8)[0-9]{9}$/,
    'entry_time': '@date(yyyy-MM-dd)'
  }]
})
export default [
  // 用户分页
  {
    url: '/user/getPageList',
    type: 'post',
    response: config => {
      let { pageSize = 10, currentPage = 1 } = config.body
      const total = userList.list.length
      let list = userList.list.slice(pageSize * (currentPage - 1), currentPage * pageSize)
      return {
        code: 20000,
        data: {
          list,
          currentPage,
          pageSize,
          totalCount: total,
          totalPages: (total + pageSize - 1) / pageSize,
        }
      }
    }
  },

  //用户删除
  {
    url: '/user/del',
    type: 'post',
    response: config => {
      const { userId } = config.body
      if (!userId) {
        return {
          code: 403,
          msg: '删除失败',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
        data: userId
      }
    }
  },
  // 用户修改
  {
    url: '/user/update',
    type: 'post',
    response: config => {
      const { user, roleIds } = config.body
      if (!user.account || !roleIds) {
        return {
          code: 20203,
          msg: 'user and roleIds is require',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
      }
    }
  },

]